package com.hibernate.persistence.lifecycle;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class DeleteEntity {

	private static SessionFactory factory = new Configuration().configure().buildSessionFactory();
	private static Session session;

	public static void main(String[] args) {
		
		deleteEmail(1);
	}

	public static void deleteMessage(int id) {
		System.out.println("---- Delete Message ----");
		session = factory.openSession();
		session.beginTransaction();
		Message message = new Message("");
		message.setId(id);
		session.delete(message);
		session.getTransaction().commit();
		session.close();
		System.out.println("---- End Delete Message ----");
	}

	public static void deleteEmail(int id) {
		System.out.println("---- Delete Email ----");
		session = factory.openSession();
		session.beginTransaction();
		Email e = new Email();
		Message m = new Message();
		m.setId(1);
		e.setId(id);
		e.setMessage(m);
		session.delete(e);
		session.getTransaction().commit();
		session.close();
		System.out.println("---- End Delete Email ----");
	}

}
